package portal.util;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;

public class PaserPage {
    public static JSONArray returnCurrentDataList(int currentPage,int onePageCount,JSONArray allDataList){
        int dataSize = allDataList.size();
        // 确定返回list的大小
        int size = 0;
        int temp = dataSize - (currentPage-1) * onePageCount;
        if(temp > onePageCount){
            size = onePageCount;
        }else {
            size = temp;
        }
        // 确定返回list的开始索引
        int startIndex = (currentPage-1)*onePageCount;
        // 循环加入list
        ArrayList<JSONObject> list = new ArrayList<>();

        for(int i =0;i<size;i++){
            JSONObject json = allDataList.getJSONObject(i+startIndex);
            list.add(json);
        }
        JSONArray currentDataList = JSONArray.fromObject(list);

        return currentDataList;
    }

//    // 测试
//    public static void main(String[] args) {
//        int currentPage = 3;
//        int onePageCount = 10;
//
//        ArrayList<JSONObject> queueslist = new ArrayList<>();
//
//        for(int i =0;i<23;i++){
//            JSONObject content1 = new JSONObject();
//            content1.put("QUEUE_NAME","test"+i);
//            content1.put("PRIO","40");
//            content1.put("STATUS","Open:Active");
//            content1.put("MAX","-");
//            content1.put("JL/U","-");
//            content1.put("JL/P","-");
//            content1.put("JL/H","-");
//            content1.put("NJOBS","0");
//            content1.put("PEND","0");
//            content1.put("RUN","0");
//            content1.put("SUSP","0");
//
//            queueslist.add(content1);
//        }
//
//        JSONArray allDataList = JSONArray.fromObject(queueslist);
//        System.out.println("all:"+allDataList);
//
//        JSONArray currentDataList = returnCurrentDataList(currentPage,onePageCount,allDataList);
//        System.out.println("fact:"+currentDataList);
//
//
//    }




}
